"""
---------------------------------------------------------------------
- File: menu.py
- Date: 2025/9/26
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 菜单模型
---------------------------------------------------------------------
"""

from enum import Enum

from tortoise import fields
from app.models.base_models import IdTimestampMixin


class MenuType(str, Enum):
    """菜单目录枚举"""

    catalog = "1"  # 目录
    menu = "2"  # 菜单


class MenuStatus(str, Enum):
    """菜单状态枚举"""

    enable = "1"  # 启用
    disable = "2"  # 禁用


class Menu(IdTimestampMixin):
    menu_name = fields.CharField(max_length=100, description="菜单名称")
    menu_type = fields.CharEnumField(MenuType, description="菜单类型")
    route_name = fields.CharField(max_length=100, description="路由名称")
    route_path = fields.CharField(max_length=200, description="路由路径")
    component = fields.CharField(null=True, max_length=100, description="路由组件")
    order = fields.IntField(default=0, description="菜单顺序")
    parent_id = fields.IntField(default=0, max_length=10, description="父菜单ID")
    menu_meta = fields.JSONField(default={}, null=True, description="菜单元数据")
    icon = fields.CharField(null=True, max_length=100, description="菜单图标")
    status = fields.CharEnumField(
        MenuStatus, default=MenuStatus.enable, description="状态"
    )
    redirect = fields.CharField(null=True, max_length=200, description="重定向路径")
    constant = fields.BooleanField(default=False, description="是否为公共路由")

    class Meta:
        table = "menu"
        orm_mode = True

    def __str__(self):
        return self.menu_name

    def __repr__(self):
        return f"<Menu:,{self.menu_name}>"
